﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RN.ERP.Web.ModelService;
using Newtonsoft.Json;
using Fly.Common.Linq;
using Fly.Common.WorkFlow;
using Telerik.Web.UI;
using Telerik.Web.UI.Skins;
using System.Text;

namespace RN.ERP.Web.Enterprise
{
    public partial class EnterpriseUpdateCorpInfoList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindAreas();
            }
        }

        protected void ListCorps_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            int pageIndex = ListCorps.CurrentPageIndex+1;
            int pageSize = ListCorps.PageSize;
            MakeKeyInfosCondition model = new MakeKeyInfosCondition();
            string corpName = txtCorpName.Text.Trim();
            int classID = Convert.ToInt32(ddlCorpType.SelectedValue);
            string areaCode = ddlAreaCode.SelectedValue;
            BindData(corpName,pageIndex,pageSize,classID,areaCode);
        }

        protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
        {
            if (e.Argument == "Rebind")
            {
                ListCorps.MasterTableView.SortExpressions.Clear();
                ListCorps.MasterTableView.GroupByExpressions.Clear();
                ListCorps.Rebind();
            }
        }

        protected void BindData(string corpName,int pageIndex,int pageSize,int classID,string areaCode)
        {
            EnterpriseService.EnterpriseServiceClient client = new EnterpriseService.EnterpriseServiceClient();
            int count;
            var KeyInfos = client.GetCorpListLC(out count, pageIndex, pageSize, corpName, classID, areaCode);
            List<CompanyInfo> list=new List<CompanyInfo>();
            list = JsonConvert.DeserializeObject<List<CompanyInfo>>(KeyInfos);
            ListCorps.DataSource = list;
            ListCorps.VirtualItemCount = count;
        }

        private void BindAreas()
        {
            BasicService.BasicServiceClient client = new BasicService.BasicServiceClient();
            List<a_AreaSubInfo> areas = JsonConvert.DeserializeObject<List<a_AreaSubInfo>>(client.GetQu("14"));
          
            ddlAreaCode.DataValueField = "SortCode";
            ddlAreaCode.DataTextField = "Title";
            ddlAreaCode.DataSource = areas;
            ddlAreaCode.DataBind();
            ddlAreaCode.Items.Insert(0, new ListItem("全部", ""));
        }

        protected string TranCorpTypeByClassid(object classid)
        {
            if (classid == null)
            {
                return string.Empty;
            }
            else
            {
                string classidStr = classid.ToString();
                string rst = string.Empty;
                switch (classidStr)
                {
                    case "2501":
                    case "25010":
                        rst = "施工企业";
                        break;
                    case "2506":
                    case "25060":
                        rst = "装饰装修企业";
                        break;
                    case "2301":
                    case "23010":
                        rst = "门窗企业";
                        break;
                    case"30":
                    case"300":
                        rst = "商砼企业";
                        break;
                    default:
                        break;
                }
                return rst;
            }
        }

    }
}